package com.yamaikeji.quartz.task;

import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
import com.yamaikeji.common.utils.StringUtils;
import com.yamaikeji.system.domain.plan.Task;
import com.yamaikeji.system.domain.plan.User;
import com.yamaikeji.system.service.plan.ITaskService;
import com.yamaikeji.system.service.plan.IUserService;
import com.yamaikeji.system.util.PushUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author yamaikeji
 */
@Component("pushBeginTask")
public class PushBeginTask {

    @Autowired
    private IUserService pUserService;

    @Autowired
    private ITaskService pTaskService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        User user = new User();
        List<User> userList = pUserService.selectUserList(user);
        for (User p : userList) {
            if ("1".equals(p.getSetTipBeginFlag())) {
                Task task = new Task();
                task.setUserNo(p.getUserNo());
                task.setTaskTime(LocalDate.now());
                task.setTaskStatus("0");
                List<Task> taskList = pTaskService.selectTaskList(task);
                Alert alert = new Alert();
                alert.setTitle("叮咚待办");
                alert.setBody("待办提醒：今日待办" + (CollectionUtils.isNotEmpty(taskList) ? taskList.size() : 0) + "条");
                PushUtil.pushMsg(p.getUserNo(), alert);
            }
        }
        System.out.println("执行无参方法");
    }
}
